﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

using Api.Hub.Models;

namespace Api.SelfHost.Controllers
{
    public class TeacherController : ApiController
    {
        static List<Teacher> teachers = new List<Teacher>();

        static TeacherController()
        {
            teachers.Add(new Teacher() { TeacherNO = "t001", Name = "老师1", Identity = 001, Age = 1, Sex = 1 });
            teachers.Add(new Teacher() { TeacherNO = "t002", Name = "老师2", Identity = 002, Age = 2, Sex = 1 });
        }

        public HttpResponseMessage Get(int? id = null)
        {
            var _teachers = teachers;

            if (id.HasValue)
            {
                var _id = id.GetValueOrDefault();
                if (_id > 0)
                {
                    _teachers = teachers.Where(f => f.Identity == _id).ToList();
                }
            }

            return Request.CreateResponse<List<Teacher>>(HttpStatusCode.OK, _teachers);
        }
    }
}
